/*
 * Copyright (c) 2006-2021, Ulandlink Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-10-18     lfz         first version
 */

#ifndef __AT_DEVICE_ESP32_H__
#define __AT_DEVICE_ESP32_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>

#include <at_device.h>

/* The maximum number of sockets supported by the esp32 device */
#define AT_DEVICE_ESP32_SOCKETS_NUM  5

#ifndef WIFI_SSID_MAX_LENGTH
#define WIFI_SSID_MAX_LENGTH  (32)   /* SSID MAX LEN */
#endif

#ifndef WIFI_PWD_MAX_LENGTH
#define WIFI_PWD_MAX_LENGTH  (32)   /* password MAX LEN */
#endif

#define ESP32_DEIVCE_NAME  "esp32"

typedef struct wifi_ssid
{
    rt_uint8_t ssid_len;
    char ssid_val[WIFI_SSID_MAX_LENGTH + 1];
}wifi_ssid_t;

typedef struct wifi_key
{
    rt_uint8_t pwd_len;
    char pwd_val[WIFI_PWD_MAX_LENGTH + 1];
}wifi_key_t;

struct at_device_esp32
{
    char *device_name;
    char *client_name;

    int power_pin;
    int reset_pin;
    wifi_ssid_t ssid;
    wifi_key_t password;
    size_t recv_line_num;
    struct at_device device;

    void *user_data;
};

#ifdef AT_USING_SOCKET

/* esp32 device socket initialize */
int esp32_socket_init(struct at_device *device);

/* esp32 device class socket register */
int esp32_socket_class_register(struct at_device_class *class);

/* esp32 device register */
int esp32_device_class_register(void);
int esp32_device_register(void);

rt_bool_t get_wifi_status(void);

esp32_device_info esp32_device_get_info(void);
rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeout);
#endif /* AT_USING_SOCKET */

#ifdef __cplusplus
}
#endif

#endif /* __AT_DEVICE_ESP32_H__ */
